<?php
namespace cus;

use think\Db;

final class Resolve
{


    ///采集页面内容
    public function resolveDefault(){
        ///抓取页面内容
        $res = file_get_contents('D:\WWW\xahy-simple-nav-pro\public\template\default\index\index.html');

        ///匹配页面内容
        $zz = '/<a href="http(.*)" target="_blank" rel="noopener">(.*)<\/a>/Us';
        preg_match_all($zz, $res, $arr);

        ///入库
        $size = count($arr[1]);
        for($i=0;$i<$size;$i++){
            if(isset($arr[2][$i])&&isset($arr[1][$i])){
                $data = ['web_title' =>$arr[2][$i], 'web_url' => 'http'.$arr[1][$i]];
                Db::table('dh_web')->insert($data);
            }
        }

        ///修改描述
        for($j=0;$j<$size;$j++){
            Db::table('dh_web')->where('web_title', $arr[2][$j])->update(['web_description' => $arr[2][$j]]);
        }

        ///客户端响应成功
        var_dump('success');
    }



}